package com.hj.security.utils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.hj.security.domain.constant.SecurityConstant;
import jakarta.servlet.http.HttpServletRequest;

/**
 * @author hj
 * @Date 2023/4/26
 * @Description: token工具类
 */
public class TokenUtils {

    /**
     * 生成 AccessToken
     */
    public static String generator() {
        return  IdUtil.fastSimpleUUID();
    }

    /**
     * 获取 AccessToken
     */
    public static String getAccessToken(HttpServletRequest request) {
        String accessToken = request.getHeader(SecurityConstant.AUTHORIZATION);
        if (StrUtil.isBlank(accessToken)) {
            accessToken = request.getParameter(SecurityConstant.ACCESS_TOKEN);
        }
        return accessToken;
    }


}
